/* 使用替换的必须用这个 */

#define NOT_REPLACE_USABLE_SIZE
#include "base_malloclib.h"
#define METALC_DYNLIB
#include <metalc/mladt/wcet_stat.h>
#include <metalc/mlos/tsysmalloc.h>


/* 定义mtls */
/* tapdsnode, 如果使用就需要 */

/* 定义pre allocator依赖 */
// #define ZPOOL_SIZE  (2 * 1024 * 1024)
// DEF_WMSP_OBJ_CACHED(mlcc_wmsp, &mtls_get()->apdstls.free_list, HDEF_CACHE_LINE_BYTES, ZPOOL_SIZE)
// DECL_INIT(mlcc_wmsp)
// SAI void mlcc_wmsp_procinit(){
//	 int madv_ret = madvise(&mlcc_wmsp_wmsp_poolmem, ZPOOL_SIZE, 14);
//	 if (madv_ret)
//		 fprintf(stderr, "madvise hugepage failed %d\n", madv_ret);
//	 fprintf(stderr, "madvise hugepage success\n");
// }
// SAI void mlcc_wmsp_threadinit(){

// }
// SAI void *apdsnode_alloc(size_t size){ return (void *)mlcc_wmsp_cachealloc(); }\
// SAI void apdsnode_free(void *ptr, size_t size){ mlcc_wmsp_cachefree((wmobj_t*)ptr); }
// SAI void *mlcc_palloc(size_t size){  return mlcc_wmsp_palloc(size); }

// DEF_MLCC_DEPS_DEFAULT(2 * 1024 * 1024, 1)

// DEF_APDSNODE_SPSLAB(tapdsnode, HDEF_CACHE_LINE_BYTES, 32768)
// /* 128KB, 可以容纳多少个线程? */
// DEF_POBJ_PHEAP(mlcc, 128 * 1024)
// SAI void *mlcc_palloc(size_t size){ fprintf(stderr, "mlcc alloc %lu\n", size); return pheap_palloc_mlcc(size); }

/* 定义allocator */
COMPOSE_MLAYER(wcetm, mallocapi, wcet, tsysmalloc)

/* 定义mtls */

// DEF_MTLS_PTHREAD(MLAYER_OBJNR, 4096, mlcc_palloc)

DEF_MTLS_PTHREAD(GET_MLAYER_OBJNR(wcetm), QUERY_CPUFREQ, mlcc_palloc, mp_coreid)
// DEF_ALLOCATOR_MTLS_DEFAULT(__this_allocator)
/* 定义进程初始化过程 */
// DEF_INIT(tapdsnode, mtls, __this_allocator)
// DEF_INIT(mlcc_wmsp, mtls, __this_allocator)
/* mlcc和mtls一定要放在第一位初始化 */
DEF_SYSINIT(malloc_perm_pool, wcetm, mtls)
DEF_CFLOWFIN(mtls)
DEF_CFLOWINIT(mtls, wcetm)
DEF_SYSFIN(__omega)
/* 初始化过程中不能使用带tls的???可能触发malloc */

/* tls其实没问题? 问题是调用pthread_setspecific的时机？？*/